//
//  SYDNetwork.m
//  PinGJByOwnerSide
//
//  Created by lantaiyuan on 2017/8/5.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "SYDNetwork.h"

@interface SYDNetwork()
@property(nonatomic, strong) SYDAccount *account;
@end

@implementation SYDNetwork
static SYDNetwork *_manager;
+ (instancetype)shareTool
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _manager = [SYDNetwork manager];
        // 设置超时时间
        _manager.requestSerializer.timeoutInterval = 30.0f;
        _manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/xml", @"text/plain", @"application/javascript", @"text/js", nil];
    });
    return _manager;
}

- (SYDAccount *)account{
    if (!_account) {
        _account = [SYDAccountTool getAccount];
    }
    return _account;
}


#pragma mark---个人中心
/**
 意见反馈
 @param cityCode 城市编码
 @param contactChannel 联系方式
 @param problemType 问题属性
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)getMineSuggestAdditionWithCityCode:(NSString *)cityCode contactChannel:(NSString *)contactChannel feedbackContent:(NSString *)feedbackContent problemType:(NSString *)problemType userId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"cityCode":cityCode == nil ?@"":cityCode,
                            @"contactChannel":contactChannel == nil ?@"":contactChannel,
                            @"problemType":problemType == nil ?@"":problemType,
                            @"userId":userId == nil ?@"":userId,
                            @"feedbackContent":feedbackContent == nil ?@"":feedbackContent
                            };
    NSString *urlStr = @"mine/sug/addition";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
/**
 提现操作
 @param cityCode 城市编码
 @param amount 提现金额
 @param bankCard 银行卡号码
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)getMineCashingAdditionWithCityCode:(NSString *)cityCode
                                   amount:(NSString *)amount
                                 bankCard:(NSString *)bankCard
                                   userId:(NSString *)userId
                                  success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"cityCode":cityCode == nil ?@"":cityCode,
                            @"amount":amount == nil ?@"":amount,
                            @"bankCard":bankCard == nil ?@"":bankCard,
                            @"userId":userId == nil ?@"":userId
                            };
    NSString *urlStr = @"mine/order/cashing/addition";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
    
}
/**
 获取体现详情
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)getMineCashingDetailAdditionWithuserId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"mine/order/cashing/%@",userId];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
/**
 根据userId查询我的钱包明细
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)getMineWalletDetailWithuserId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
   
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"mine/wallet/detail/%@",userId];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
/**
 根据userId获取个人账号信息
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)getMineAcountWithUserId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"mine/account/%@",userId];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
/**
 根据userId获取个人资料
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)getMineMaterialWithUserId:(NSString *)userId cityCode:(NSString *)cityCode success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"mine/material/%@/%@",userId,cityCode];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
/**
 根据userId获取我的行程
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)getMyTrailOrderWithUserId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
   
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"mine/mytrail/order/%@",userId];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
/**
 根据userId获取我的车辆
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)getMineBusIfonWithUserId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{

    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"mine/bus/%@",userId];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
/**
 根据userId获取我的钱包
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)getMineWalletWithUserId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"mine/wallet/%@",userId];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
   
}
/**
 行程轨迹
 @param orderNo 顺风车订单号
 @param success 成功
 @param failure 失败
 */
-(void)getMyTrailDetailWithOrderNo:(NSString *)orderNo success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"mine/mytrail/detail/%@",orderNo];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
/**
 设置或重置支付密码
 @param cityCode 城市编码
 @param payCode 支付密码
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)setPayCodeAccountWithCityCode:(NSString *)cityCode payCode:(NSString *)payCode userId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"cityCode":cityCode == nil ?@"":cityCode,
                            @"payCode":payCode == nil ?@"":payCode,
                            @"userId":userId == nil ?@"":userId
                            };
    NSString *urlStr = @"mine/account/paycode/set";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
/**
 重置登录密码
 @param cityCode 城市编码
 @param password 登录密码
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)SetMineAccountPwdWithCityCode:(NSString *)cityCode oldPwd:(NSString *)oldPwd password:(NSString *)password userId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"cityCode":cityCode == nil ?@"":cityCode,
                            @"password":password == nil ?@"":password,
                            @"userId":userId == nil ?@"":userId,
                            @"oldPwd":oldPwd == nil ?@"":oldPwd
                            };
    NSString *urlStr = @"mine/account/pwd/set";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
/*
 校验支付密码的正确性
 */
-(void)paycodeValidationWithCityCode:(NSString *)cityCode
                             payCode:(NSString *)payCode
                              userId:(NSString *)userId
                             success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                             failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"mine/account/paycode/validation?cityCode=%@&payCode=%@&userId=%@",cityCode,payCode,userId];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
#pragma mark---杨阳
/**
 成绩统计
 @param success 成功
 @param failure 失败
 */
- (void)getHomeTodayDataSuccess:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"stat/curday/statline/%@",self.account.userId];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
/**
 消息通知
 @param cityCode 城市编码
 @param success 成功
 @param failure 失败
 */
-(void)GetHomePageMsgWithCityCode:(NSString *)cityCode success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"homepage/msg/%@",cityCode];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
/**
 校验支付密码的正确性
 @param cityCode 城市编码
 @param payCode 支付密码
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)CheckPayCodeValidationWithCityCode:(NSString *)cityCode payCode:(NSString *)payCode userId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"cityCode":cityCode == nil ?@"":cityCode,
                            @"payCode":payCode == nil ?@"":payCode,
                            @"userId":userId == nil ?@"":userId
                            };
    NSString *urlStr = @"mine/account/paycode/validation";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
#pragma mark---三斌
/**
 用户登录
 @param password 密码
 @param username 用户名
 @param success 成功
 @param failure 失败
 */
-(void)UserLoginWithPassword:(NSString *)password username:(NSString *)username success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"username":username == nil ?@"":username,
                            @"password":password == nil ?@"":password
                            };
    NSString *urlStr = @"login/userLogin";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
/**
 忘记密码
 @param password 密码
 @param username 账号
 @param smsCode 验证码
 @param success 成功
 @param failure 失败
 */
-(void)RetrievePasswordWithPassword:(NSString *)password username:(NSString *)username smsCode:(NSString *)smsCode success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{

    NSDictionary *value = @{
                            @"username":username == nil ?@"":username,
                            @"password":password == nil ?@"":password,
                            @"smsCode":smsCode == nil ? @"":smsCode
                            };
    NSString *urlStr = @"login/retrievePassword";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
/**
 获取短信码
 @param mobilePhone 电话号码
 @param smsType 验证码
 @param success 成功
 @param failure 失败
 */
-(void)getSmsCodeWithMobilePhone:(NSString *)mobilePhone smsType:(NSString *)smsType success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"mobilePhone":mobilePhone == nil ?@"":mobilePhone,
                            @"smsType":smsType == nil ? @"":smsType
                            };
    NSString *urlStr = @"public/getSmsCode";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
/*
 账户注册
 */
-(void)userRegisterWithSMSCode:(NSString *)SMSCode username:(NSString *)username password:(NSString *)password success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
   
    NSDictionary *value = @{
                            @"SMSCode":SMSCode == nil ?@"":SMSCode,
                            @"username":username == nil ? @"":username,
                            @"password":password == nil ? @"" : password
                            };
    NSString *urlStr = @"register/userRegister";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
/*
 注册详情步骤---身份信息 驾驶证信息  行驶证信息  车辆信息
 */
-(void)userInfoRegisterWithRegisterStep:(NSString *)registerStep realName:(NSString *)realName cardId:(NSString*)cardId iconUrl:(NSString *)iconUrl IDPhotoFrontUrl:(NSString *)IDPhotoFrontUrl IDPhotoBackUrl:(NSString *)IDPhotoBackUrl busBrand:(NSString *)busBrand busLicensePlate:(NSString *)busLicensePlate busOwner:(NSString *)busOwner carPhotoUrl:(NSString *)carPhotoUrl cityBelong:(NSString *)cityBelong cityCode:(NSString *)cityCode firmBelong:(NSString *)firmBelong passengerCountPermitted:(NSString *)passengerCountPermitted drivingLicenceStartTime:(NSString *)drivingLicenceStartTime drivinglicenceBackUrl:(NSString *)drivinglicenceBackUrl drivinglicenceFrontUrl:(NSString *)drivinglicenceFrontUrl runningLicenceRegisterTime:(NSString *)runningLicenceRegisterTime runningLicenceBackUrl:(NSString *)runningLicenceBackUrl runningLicenceFrontUrl:(NSString *)runningLicenceFrontUrl userId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    
    NSDictionary *value;
    if ([registerStep integerValue] == 1) {
        value = @{@"registerStep":registerStep == nil ?@"":registerStep,
                  @"identityInformation":@{@"IDPhotoBackUrl":IDPhotoBackUrl == nil ?@"":IDPhotoBackUrl,
                                           @"IDPhotoFrontUrl":IDPhotoFrontUrl == nil ?@"":IDPhotoFrontUrl,
                                           @"cardId":cardId == nil ?@"":cardId,
                                           @"iconUrl":iconUrl == nil ?@"":iconUrl,
                                           @"realName":realName == nil ?@"":realName,
                                           @"userId":userId == nil ? @"" : userId
                                           }
                  };
    }else if ([registerStep integerValue] == 2){
        value = @{@"registerStep":registerStep == nil ?@"":registerStep,
                  @"drivingLicence":@{@"drivingLicenceStartTime":drivingLicenceStartTime == nil ?@"":drivingLicenceStartTime,
                                      @"drivinglicenceBackUrl":drivinglicenceBackUrl == nil ?@"":drivinglicenceBackUrl,
                                      @"drivinglicenceFrontUrl":drivinglicenceFrontUrl == nil ?@"":drivinglicenceFrontUrl,
                                      @"userId":userId == nil ? @"" : userId
                                      }
                  };
    }else if ([registerStep integerValue] == 3){
        value = @{@"registerStep":registerStep == nil ?@"":registerStep,
                  @"runningLicence":@{@"runningLicenceRegisterTime":runningLicenceRegisterTime == nil ?@"":runningLicenceRegisterTime,
                                    @"runningLicenceBackUrl":runningLicenceBackUrl == nil ?@"":runningLicenceBackUrl,
                                      @"runningLicenceFrontUrl":runningLicenceFrontUrl == nil ?@"":runningLicenceFrontUrl,
                                      @"userId":userId == nil ? @"" : userId
                                      }
                  };
    }else if ([registerStep integerValue] == 4){
       
        value = @{@"registerStep":registerStep == nil ?@"":registerStep,
                  @"carInformation":@{@"busBrand":busBrand == nil ?@"":busBrand,
                                      @"busLicensePlate":busLicensePlate == nil ?@"":busLicensePlate,
                                      @"busOwner":busOwner == nil ?@"":busOwner,
                                      @"carPhotoUrl":carPhotoUrl == nil ?@"":carPhotoUrl,
                                      @"cityBelong":cityBelong == nil ?@"":cityBelong,
                                      @"cityCode":cityCode == nil ?@"":cityCode,
                                      @"firmBelong":firmBelong == nil ?@"":firmBelong,
                                      @"passengerCountPermitted":passengerCountPermitted == nil ?@"":passengerCountPermitted,
                                      @"userId":userId == nil ? @"" : userId
                                      }
                  };
    }

    NSString *urlStr = @"register/userInfoRegister";
    NSDictionary *params = @{@"data":[value mj_JSONString]};

    [self kPOST:urlStr parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
#pragma mark---表单上传
/**单张表单上传图片 */
- (void)uploadMultipartFilesWithParameters:(NSDictionary *)parameters
                                     mFile:(NSString *)mFile
                                uploadData:(NSData *)uploadData
                                   success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                                   failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    
    [self UploadPostUrlStr:@"public/uploadMultipartFiles" parameters:nil mFile:mFile uploadData:uploadData success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
// 上传多张图片
-(void)uploadMostMultipartFilesWithParameters:(id)parameters
                                        mFile:(NSString *)mFile
                                  uploadDatas:(NSArray *)uploadDatas
                                      success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                                      failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
     [self UploadMostPostUrlStr:@"mine/sug/addition" parameters:parameters mFile:mFile uploadData:uploadDatas success:^(NSURLSessionDataTask *task, id responseObject) {
         success(task,responseObject);
     } failure:^(NSURLSessionDataTask *task, NSError *error) {
         failure(task,error);
     }];
}


/*
 获取短信验证码(忘记密码)
 */
-(void)getLoginSmsCodeWithMobilePhone:(NSString *)mobilePhone
                              success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                              failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"mobilePhone":mobilePhone == nil ?@"":mobilePhone
                            };
    NSString *urlStr = @"login/getLoginSmsCode";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
    
}

/*
 获取注册短信验证码
 */
- (void)getRegisterSmsCodeWithMobilePhone:(NSString *)mobilePhone
                              success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                              failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"mobilePhone":mobilePhone == nil ?@"":mobilePhone
                            };
    NSString *urlStr = @"register/getLoginSmsCode";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}

/*
 获取短信验证码
 */
-(void)getLoginSmsCodeWithMobilePhone:(NSString *)mobilePhone
                              smsType:(NSString *)smsType
                              success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                              failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"mobilePhone":mobilePhone == nil ?@"":mobilePhone,
                            @"smsType":smsType == nil ? @"":smsType
                            };
    NSString *urlStr = @"register/getLoginSmsCode";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}


/**
 get pay sms code
 
 @param mobile mobile
 */
- (void)getPaySmsCodeWithMobile:(NSString *)mobile
                        success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                        failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"mobilePhone":mobile == nil ?@"":mobile
                            };
    NSString *urlStr = @"mine/getPayPayCodeSmsCode";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}


/**
 varification pay sms code

 @param mobile mobile
 @param sms sms code
 */
- (void)verificationPaySmsWithMobile:(NSString *)mobile
                                 sms:(NSString *)sms
                             success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                             failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"mobilePhone":mobile == nil ?@"":mobile,
                            @"smsCode":sms
                            };
    NSString *urlStr = @"mine/checkPayPayCodeSmsCode";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}

/*
 更改车主当前状态
 */
-(void)changeBusOwnerStatusWithCityCode:(NSString *)cityCode
                                 status:(NSString *)status
                                 userId:(NSString *)userId success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                                failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSDictionary *value = @{
                            @"cityCode":cityCode == nil ?@"":cityCode,
                            @"status":status == nil ? @"":status,
                            @"userId":userId == nil ? @"":userId
                            };
    NSString *urlStr = @"homepage/changeBusOwnerStatus";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
    
}
/**
 根据用户Id获取车主最近一次接单号
 */
-(void)getOrderSuccess:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    
    NSString *urlStr = @"homepage/getOrderNoByUserId";
    NSString *params = [NSString stringWithFormat:@"userId=%@",self.account.userId];
    [self kGET:urlStr parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
    
}
#pragma mark---城市选择
/**
 获取已开通城市列表(备选城市)
 
 @param success 成功
 @param failure 失败
 */
- (void)getCityListWithVersion:(NSString *)version success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    
    NSString *urlStr = @"http://10.1.254.79/serviceIp/cities";
    NSString *params = [NSString stringWithFormat:@"version=%@",version];
    [self kGET:urlStr parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
}
/**
 去接乘客-开始行程
 @param cityCode 城市编码
 @param lat 车辆纬度
 @param lon 车辆经度
 @param orderNo 顺风车订单号
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)startJourneyWithCityCode:(NSString *)cityCode
                                                       lat:(NSString *)lat
                                                       lon:(NSString *)lon
                                                   orderNo:(NSString *)orderNo
                                                    userId:(NSString *)userId
                                                   success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                                                   failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    
    NSDictionary *value = @{
                            @"cityCode":cityCode == nil ?@"":cityCode,
                            @"lat":lat == nil ? @"":lat,
                            @"lon":lon == nil ? @"":lon,
                            @"orderNo":orderNo == nil ? @"":orderNo,
                            @"userId":userId == nil ? @"":userId
                            };
    NSString *urlStr = @"homepage/pickUpPassengers/startJourney";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
  
}
/**
 去接乘客-结束行程
 @param cityCode 城市编码
 @param lat 车辆纬度
 @param lon 车辆经度
 @param orderNo 顺风车订单号
 @param userId 用户id
 @param success 成功
 @param failure 失败
 */
-(void)endJourneyWithCityCode:(NSString *)cityCode
                                                     lat:(NSString *)lat
                                                     lon:(NSString *)lon
                                                 orderNo:(NSString *)orderNo
                                                  userId:(NSString *)userId
                                                 success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                                                 failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    
    NSDictionary *value = @{
                            @"cityCode":cityCode == nil ?@"":cityCode,
                            @"lat":lat == nil ? @"":lat,
                            @"lon":lon == nil ? @"":lon,
                            @"orderNo":orderNo == nil ? @"":orderNo,
                            @"userId":userId == nil ? @"":userId
                            };
    NSString *urlStr = @"homepage/pickUpPassengers/endJourney";
    [self kPOST:urlStr parameters:value success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(task,error);
    }];
   
}
/**
 去接乘客-确定完成行程
 @param success 成功
 @param failure 失败
 */
-(void)confirmEndingJourneySuccess:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                           failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"homepage/pickUpPassengers/confirmEndingJourney/%@",[YMOrderTool getOrderNo]];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
}
/**
 去接乘客-线路详情
 @param orderNo 顺风车订单号
 @param success 成功
 @param failure 失败
 */
-(void)GetHomepagePickUpPassengersRouteDetailWithorderNo:(NSString *)orderNo
                                                 success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                                                 failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    //设置请求体
    NSString *urlStr = [NSString stringWithFormat:@"homepage/pickUpPassengers/routeDetail/%@",orderNo];
    [self kGET:urlStr parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        failure(task,error);
    }];
   
}
#pragma mark - System Methods
#pragma mark - 表单POST请求
-(void)UploadPostUrlStr:(NSString *)URLString
             parameters:(NSDictionary *)parameters
                  mFile:(NSString *)mFile
             uploadData:(NSData *)uploadData
                success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success
                failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSString * url = [BASE_URL stringByAppendingString:URLString];
    NSLog(@"-->表单post链接:%@?%@",url,parameters);
   [self POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
       [formData appendPartWithFileData:uploadData name:@"mFile" fileName:@"1.jpg" mimeType:@"image/jpg"];
       NSLog(@"formData:%@",formData);
   } progress:^(NSProgress * _Nonnull uploadProgress) {
       NSLog(@"---上传进度--- %f",uploadProgress.fractionCompleted);
   } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       success(task,responseObject);
   } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       failure(task, error);
   }];
}
//多张图片上传
-(void)UploadMostPostUrlStr:(NSString *)URLString
             parameters:(NSDictionary *)parameters
                  mFile:(NSString *)mFile
             uploadData:(NSArray *)uploadData
                success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success
                failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    NSString * url = [BASE_URL stringByAppendingString:URLString];
    
    [self POST:url parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        if (uploadData.count >= 1) {
            __block NSInteger i = 0;
            for (id value in uploadData) {
                if ([value isKindOfClass:[NSData class]]) {//是否二进制文件
                    [formData appendPartWithFileData:value name:@"mFile" fileName:[NSString stringWithFormat:@"%ld.jpg",i+1] mimeType:@"image/jpg"];
                }else if ([value isKindOfClass:[UIImage class]]){//如果不是二进制数据进行转换
                    [formData appendPartWithFileData:[self image_TransForm_Data:value] name:@"mFile" fileName:[NSString stringWithFormat:@"%ld.jpg",i+1] mimeType:@"image/jpg"];
                }
                i++;
            }
        }
        NSLog(@"formData:%@",formData);
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        NSLog(@"---上传进度--- %f",uploadProgress.fractionCompleted);
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(task, error);
    }];
}
#pragma mark---图片转化
-(NSData *)image_TransForm_Data:(UIImage *)image{
    NSData *data = UIImageJPEGRepresentation(image, 0.5);
    return data;
}
- (void)kPOST:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure{
    
    NSString *url;
    if ([URLString hasPrefix:@"http"] == YES) {//测试
        url = URLString;
    }else{
        url = [BASE_URL stringByAppendingString:URLString];
    }
    NSLog(@"-----host地址:%@",url);
    NSLog(@"---参数:%@",[parameters mj_JSONString]);
    [self POST:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"Error:%@",error.description);
        failure(task, error);
    }];
}
#pragma mark--- 一期Get请求
- (void)kGET:(NSString *)URLString
  parameters:(nullable id)parameters
     success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success
     failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure{
    
    NSString *urlStr;
    if ([URLString hasPrefix:@"http"] == YES) {//已经是完整地址
        urlStr = [NSString stringWithFormat:@"%@?%@",URLString,parameters];;
    }else{
        NSString * url = [BASE_URL stringByAppendingString:URLString];
        if (parameters == nil) {
            urlStr = url;
        }else{
           urlStr = [NSString stringWithFormat:@"%@?%@",url,parameters];
        }
    }
    //urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"-->链接:%@",urlStr);
    
    [self GET:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        @try {
            if ([responseObject[@"statusCode"] intValue] == 200||[responseObject[@"success"]boolValue] == 1) {
                success(task,responseObject);
            }else{
                success(task,responseObject);
            }
        } @catch (NSException *exception) {
            NSLog(@"exception:%@-%@",[exception name],[exception description]);
        } @finally {
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"Error:%@",error.description);
        failure(task, error);
    }];
}
@end
